// pages/product-list/product-list.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    prod:[],
    pIdx:'0', //产品类型
    stypeIdx:'0', //小类型
    typeList:[
      { img: '/img/product-1.png', title: '常规产品' },
      { img: '/img/product-2.png', title: '升级产品' },
      { img: '/img/product-3.png', title: '科技产品' },
      { img: '/img/product-4.png', title: '创新产品' },
      { img: '/img/product-5.png', title: '基础产品' },
      { img: '/img/product-6.png', title: '全部产品' },
    ],
    list: [ //产品列表
      { img: '/img/exam.jpg', title: '达瓦达多', text: '爆款9折' },
      { img: '/img/exam.jpg', title: '达瓦达多', text: '爆款9折' },
      { img: '/img/exam.jpg', title: '达瓦达多', text: '爆款9折' },
      { img: '/img/exam.jpg', title: '达瓦达多', text: '爆款9折' },
      { img: '/img/exam.jpg', title: '达瓦达多', text: '爆款9折' },
    ], 
    stypeList:['酒店','宾馆','更多'],
  },

  selectProductTap: function (e) { //产品类型
    console.log(e)
    let that = this;
    let idx = e.currentTarget.dataset.idx;
    console.log(idx)
    that.setData({
      pIdx: idx
    })
  },
  selectTypeTap:function(e){ //小类型
    let that = this;
    let idx = e.currentTarget.dataset.idx;
    console.log(idx)
    that.setData({
      stypeIdx:idx
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAsscoProductList(); //协会产品列表
  },

  getAsscoProductList:function(){
    let that = this;
    wx.request({
      url: app.globalData.host + 'product/getProductIndex',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "GET",
      data: {},
      success(res) {
        console.log(res)
        that.setData({
          prod: res.data.data.data
        })
      },
      fail(err) { },
      complete(comp) { },
    })

  },

  searchTap:function(e){ //搜索
    console.log(e)
    var that =this;
    var name = e.detail.value;
    console.log(name)
    wx.request({
      url: app.globalData.host + 'product/getProductIndex',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "GET",
      data: {
        name
      },
      success(res) {
        console.log(res)
        that.setData({
          prod: res.data.data.data
        })
      },
      fail(err) { },
      complete(comp) { },
    })

  },
  //协会产品详情
  openAssociaDetail: function (e) { 
    let that = this;
    let id = e.currentTarget.dataset.id;
    console.log(id)
    app.confirmLogin(
      function () {
        wx.navigateTo({
          url: '/pages/associa-product/associa-product?id=' + id,
        })
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})